//
//  ViewController.m
//  -网络请求
//
//  Created by 何典钊 on 2016/12/18.
//  Copyright © 2016年 hedianzhao. All rights reserved.
//

#import "ViewController.h"

@interface ViewController ()
@property (nonatomic, strong) UIWebView *webView;
@end

@implementation ViewController

- (void)viewDidLoad {
    [super viewDidLoad];
   
    self.webView = [[UIWebView alloc] initWithFrame:self.view.bounds];
    [self.view addSubview:_webView];
    
    [self loadBaidu];
}

- (void)loadBaidu {
    //1.创建一个URL对象
    NSURL *url = [NSURL URLWithString:@"http://www.baidu.com"];
    //2.创建一个请求对象
//    NSURLRequest *request = [NSURLRequest requestWithURL:url];
    NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:url];
    [request setValue:@"iphone AppleWebKit" forHTTPHeaderField:@"User-Agent"];
    //3.发起请求
    //ios2.0推出的网络请求的类 ios9.0才刚刚废弃
    [NSURLConnection sendAsynchronousRequest:request
                                                                    queue:[NSOperationQueue mainQueue]
    completionHandler:^(NSURLResponse * _Nullable response, NSData * _Nullable data, NSError * _Nullable connectionError) {
        if (connectionError != nil) {
            return ;
        }
        NSString *string = [[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding];
         NSLog(@"%@",string);
        
        [_webView loadHTMLString:string baseURL:url];
                           }];
}

//下滑栏关闭
- (BOOL)prefersStatusBarHidden
{
    return YES;
}

@end
